﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional

namespace BackOffice.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class InitCreate : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "AppMenus",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Name = table.Column<string>(type: "text", nullable: false),
                    Url = table.Column<string>(type: "text", nullable: true),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: true),
                    Order = table.Column<int>(type: "integer", nullable: false),
                    AppMenuId = table.Column<Guid>(type: "uuid", nullable: true),
                    Code = table.Column<string>(type: "text", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
                    CreateBy = table.Column<string>(type: "text", nullable: false),
                    UpdateBy = table.Column<string>(type: "text", nullable: false),
                    RowVersion = table.Column<byte[]>(type: "bytea", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppMenus", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AppMenus_AppMenus_AppMenuId",
                        column: x => x.AppMenuId,
                        principalTable: "AppMenus",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "AppPermissions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Name = table.Column<string>(type: "text", nullable: false),
                    Description = table.Column<string>(type: "text", nullable: false),
                    Code = table.Column<string>(type: "text", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
                    CreateBy = table.Column<string>(type: "text", nullable: false),
                    UpdateBy = table.Column<string>(type: "text", nullable: false),
                    RowVersion = table.Column<byte[]>(type: "bytea", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppPermissions", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "AppRoles",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Name = table.Column<string>(type: "text", nullable: false),
                    Description = table.Column<string>(type: "text", nullable: true),
                    Code = table.Column<string>(type: "text", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
                    CreateBy = table.Column<string>(type: "text", nullable: false),
                    UpdateBy = table.Column<string>(type: "text", nullable: false),
                    RowVersion = table.Column<byte[]>(type: "bytea", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppRoles", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "AppSystemSettings",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Key = table.Column<string>(type: "text", nullable: false),
                    Value = table.Column<string>(type: "text", nullable: false),
                    Description = table.Column<string>(type: "text", nullable: true),
                    Code = table.Column<string>(type: "text", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
                    CreateBy = table.Column<string>(type: "text", nullable: false),
                    UpdateBy = table.Column<string>(type: "text", nullable: false),
                    RowVersion = table.Column<byte[]>(type: "bytea", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppSystemSettings", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "AppUsers",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Username = table.Column<string>(type: "text", nullable: false),
                    Email = table.Column<string>(type: "text", nullable: false),
                    Phone = table.Column<string>(type: "text", nullable: true),
                    PasswordHash = table.Column<string>(type: "text", nullable: false),
                    LastLoginAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    Code = table.Column<string>(type: "text", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
                    CreateBy = table.Column<string>(type: "text", nullable: false),
                    UpdateBy = table.Column<string>(type: "text", nullable: false),
                    RowVersion = table.Column<byte[]>(type: "bytea", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppUsers", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Articles",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Title = table.Column<string>(type: "text", nullable: false),
                    Content = table.Column<string>(type: "text", nullable: false),
                    Category = table.Column<string>(type: "text", nullable: false),
                    Tags = table.Column<string>(type: "text", nullable: false),
                    Status = table.Column<int>(type: "integer", nullable: false),
                    Code = table.Column<string>(type: "text", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
                    CreateBy = table.Column<string>(type: "text", nullable: false),
                    UpdateBy = table.Column<string>(type: "text", nullable: false),
                    RowVersion = table.Column<byte[]>(type: "bytea", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Articles", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Tags",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Name = table.Column<string>(type: "text", nullable: false),
                    Code = table.Column<string>(type: "text", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
                    CreateBy = table.Column<string>(type: "text", nullable: false),
                    UpdateBy = table.Column<string>(type: "text", nullable: false),
                    RowVersion = table.Column<byte[]>(type: "bytea", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Tags", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "AppRolePermissions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    RoleId = table.Column<Guid>(type: "uuid", nullable: false),
                    PermissionId = table.Column<Guid>(type: "uuid", nullable: false),
                    Code = table.Column<string>(type: "text", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
                    CreateBy = table.Column<string>(type: "text", nullable: false),
                    UpdateBy = table.Column<string>(type: "text", nullable: false),
                    RowVersion = table.Column<byte[]>(type: "bytea", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppRolePermissions", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AppRolePermissions_AppPermissions_PermissionId",
                        column: x => x.PermissionId,
                        principalTable: "AppPermissions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_AppRolePermissions_AppRoles_RoleId",
                        column: x => x.RoleId,
                        principalTable: "AppRoles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "AppUserRoles",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    UserId = table.Column<Guid>(type: "uuid", nullable: false),
                    RoleId = table.Column<Guid>(type: "uuid", nullable: false),
                    Code = table.Column<string>(type: "text", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
                    CreateBy = table.Column<string>(type: "text", nullable: false),
                    UpdateBy = table.Column<string>(type: "text", nullable: false),
                    RowVersion = table.Column<byte[]>(type: "bytea", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppUserRoles", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AppUserRoles_AppRoles_RoleId",
                        column: x => x.RoleId,
                        principalTable: "AppRoles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_AppUserRoles_AppUsers_UserId",
                        column: x => x.UserId,
                        principalTable: "AppUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ArticleTags",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ArticleId = table.Column<Guid>(type: "uuid", nullable: false),
                    TagId = table.Column<Guid>(type: "uuid", nullable: false),
                    Code = table.Column<string>(type: "text", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
                    CreateBy = table.Column<string>(type: "text", nullable: false),
                    UpdateBy = table.Column<string>(type: "text", nullable: false),
                    RowVersion = table.Column<byte[]>(type: "bytea", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArticleTags", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ArticleTags_Articles_ArticleId",
                        column: x => x.ArticleId,
                        principalTable: "Articles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ArticleTags_Tags_TagId",
                        column: x => x.TagId,
                        principalTable: "Tags",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.InsertData(
                table: "AppMenus",
                columns: new[] { "Id", "AppMenuId", "Code", "CreateBy", "CreatedAt", "IsDeleted", "Name", "Order", "ParentId", "RowVersion", "UpdateBy", "UpdatedAt", "Url" },
                values: new object[] { new Guid("11111111-1111-1111-1111-111111111111"), null, null, "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), false, "Dashboard", 1, new Guid("11111111-1111-1111-1111-111111111111"), new byte[0], "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), "/dashboard" });

            migrationBuilder.InsertData(
                table: "AppPermissions",
                columns: new[] { "Id", "Code", "CreateBy", "CreatedAt", "Description", "IsDeleted", "Name", "RowVersion", "UpdateBy", "UpdatedAt" },
                values: new object[] { new Guid("11111111-1111-1111-1111-111111111111"), null, "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), "Permission to view the dashboard", false, "View Dashboard", new byte[0], "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301) });

            migrationBuilder.InsertData(
                table: "AppRoles",
                columns: new[] { "Id", "Code", "CreateBy", "CreatedAt", "Description", "IsDeleted", "Name", "RowVersion", "UpdateBy", "UpdatedAt" },
                values: new object[] { new Guid("11111111-1111-1111-1111-111111111111"), null, "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), "System Administrator", false, "Administrator", new byte[0], "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301) });

            migrationBuilder.InsertData(
                table: "AppSystemSettings",
                columns: new[] { "Id", "Code", "CreateBy", "CreatedAt", "Description", "IsDeleted", "Key", "RowVersion", "UpdateBy", "UpdatedAt", "Value" },
                values: new object[] { new Guid("11111111-1111-1111-1111-111111111111"), null, "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), null, false, "SiteName", new byte[0], "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), "Universal Admin System" });

            migrationBuilder.InsertData(
                table: "AppUsers",
                columns: new[] { "Id", "Code", "CreateBy", "CreatedAt", "Email", "IsDeleted", "LastLoginAt", "PasswordHash", "Phone", "RowVersion", "UpdateBy", "UpdatedAt", "Username" },
                values: new object[] { new Guid("11111111-1111-1111-1111-111111111111"), null, "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), "admin@example.com", false, new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), "113", "+1234567890", new byte[0], "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), "admin" });

            migrationBuilder.InsertData(
                table: "Articles",
                columns: new[] { "Id", "Category", "Code", "Content", "CreateBy", "CreatedAt", "IsDeleted", "RowVersion", "Status", "Tags", "Title", "UpdateBy", "UpdatedAt" },
                values: new object[,]
                {
                    { new Guid("22222222-2222-2222-2222-222222222222"), "技术", null, "富文本内容...", "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), false, new byte[0], 1, "DDD,Clean,入门", "Clean Architecture 入门", "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301) },
                    { new Guid("33333333-3333-3333-3333-333333333333"), "架构", null, "微服务落地指南...", "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), false, new byte[0], 0, "微服务,进阶", "微服务实践", "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301) }
                });

            migrationBuilder.InsertData(
                table: "Tags",
                columns: new[] { "Id", "Code", "CreateBy", "CreatedAt", "IsDeleted", "Name", "RowVersion", "UpdateBy", "UpdatedAt" },
                values: new object[,]
                {
                    { new Guid("44444444-4444-4444-4444-444444444444"), null, "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), false, "DDD", new byte[0], "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301) },
                    { new Guid("55555555-5555-5555-5555-555555555555"), null, "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), false, "Clean", new byte[0], "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301) }
                });

            migrationBuilder.InsertData(
                table: "AppRolePermissions",
                columns: new[] { "Id", "Code", "CreateBy", "CreatedAt", "IsDeleted", "PermissionId", "RoleId", "RowVersion", "UpdateBy", "UpdatedAt" },
                values: new object[] { new Guid("11111111-1111-1111-1111-111111111111"), null, "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), false, new Guid("11111111-1111-1111-1111-111111111111"), new Guid("11111111-1111-1111-1111-111111111111"), new byte[0], "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301) });

            migrationBuilder.InsertData(
                table: "AppUserRoles",
                columns: new[] { "Id", "Code", "CreateBy", "CreatedAt", "IsDeleted", "RoleId", "RowVersion", "UpdateBy", "UpdatedAt", "UserId" },
                values: new object[] { new Guid("11111111-1111-1111-1111-111111111111"), null, "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), false, new Guid("11111111-1111-1111-1111-111111111111"), new byte[0], "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), new Guid("11111111-1111-1111-1111-111111111111") });

            migrationBuilder.InsertData(
                table: "ArticleTags",
                columns: new[] { "Id", "ArticleId", "Code", "CreateBy", "CreatedAt", "IsDeleted", "RowVersion", "TagId", "UpdateBy", "UpdatedAt" },
                values: new object[,]
                {
                    { new Guid("66666666-6666-6666-6666-666666666666"), new Guid("22222222-2222-2222-2222-222222222222"), null, "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), false, new byte[0], new Guid("44444444-4444-4444-4444-444444444444"), "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301) },
                    { new Guid("77777777-7777-7777-7777-777777777777"), new Guid("22222222-2222-2222-2222-222222222222"), null, "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301), false, new byte[0], new Guid("55555555-5555-5555-5555-555555555555"), "system", new DateTime(2025, 7, 29, 7, 16, 15, 204, DateTimeKind.Utc).AddTicks(3301) }
                });

            migrationBuilder.CreateIndex(
                name: "IX_AppMenus_AppMenuId",
                table: "AppMenus",
                column: "AppMenuId");

            migrationBuilder.CreateIndex(
                name: "IX_AppRolePermissions_PermissionId",
                table: "AppRolePermissions",
                column: "PermissionId");

            migrationBuilder.CreateIndex(
                name: "IX_AppRolePermissions_RoleId",
                table: "AppRolePermissions",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserRoles_RoleId",
                table: "AppUserRoles",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserRoles_UserId",
                table: "AppUserRoles",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_ArticleTags_ArticleId",
                table: "ArticleTags",
                column: "ArticleId");

            migrationBuilder.CreateIndex(
                name: "IX_ArticleTags_TagId",
                table: "ArticleTags",
                column: "TagId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "AppMenus");

            migrationBuilder.DropTable(
                name: "AppRolePermissions");

            migrationBuilder.DropTable(
                name: "AppSystemSettings");

            migrationBuilder.DropTable(
                name: "AppUserRoles");

            migrationBuilder.DropTable(
                name: "ArticleTags");

            migrationBuilder.DropTable(
                name: "AppPermissions");

            migrationBuilder.DropTable(
                name: "AppRoles");

            migrationBuilder.DropTable(
                name: "AppUsers");

            migrationBuilder.DropTable(
                name: "Articles");

            migrationBuilder.DropTable(
                name: "Tags");
        }
    }
}
